#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int n;
int a[N];
int laz[N];
int raz[N];
int main()
{
    cin >> n;
    long long cnt = 0;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == 0)
            laz[i] = laz[i - 1] + 1;
    }
    for (int i = n; i >= 1; i--)
    {
        if (a[i] == 0)
            raz[i] = raz[i + 1] + 1;
    }
    long long l, r;
    for (int i = 1; i <= n; i++)
    {
        if (a[i])
        {
            l = (i > 1) ? laz[i - 1] + 1 : 1;
            r = (i < n) ? raz[i + 1] + 1 : 1;
            cnt += l * r;
        }
    }
    cout << cnt;
    return 0;
}




